<template>
    <div class="DatabaseTalents content-container">
        <div class="breadcrumb">数据库管理-企业管理</div>
        <div class="search_box">
            <div class="form">
                <el-form ref="form" :model="query" label-width="100px">
                    <el-row>
                        <el-col :span="6">
                            <el-form-item label="企业名称：">
                                <el-input v-model="query.fullName"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="联系人：">
                                <el-input v-model="query.contactName"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="联系电话：">
                                <el-input v-model="query.phone"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="邮箱：">
                                <el-input v-model="query.email"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="6">
                            <el-form-item label="企业类型：">
                                <DbSelector type="10" v-model="query.type"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="企业性质：">
                                <DbSelector type="11" v-model="query.nature"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="所在地：">
                                <el-input v-model="query.city"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="审核状态：">
                                <el-select style="width:100%;" v-model="query.checkState" placeholder="请选择">
                                    <el-option label="全部" :value="undefined"></el-option>
                                    <el-option label="待审核" :value="0"></el-option>
                                    <el-option label="试用合作" :value="1"></el-option>
                                    <el-option label="已合作" :value="2"></el-option>
                                    <el-option label="暂不合作" :value="3"></el-option>
                                    <el-option label="异常" :value="4"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="6">
                            <el-form-item label="顾问：">
                                <el-input v-model="query.name"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6" style="border: 2px solid white"></el-col>
                        <el-col :span="6" style="text-align: right">
                            <a href="javascript:void(0)" v-if="false">
                                <img src="@/assets/imgs/delete.jpg" alt="批量删除" @click="handleDelete">
                            </a>
                        </el-col>
                        <el-col :span="6" style="text-align:right">
                            <el-button class="btn" @click="doshowTalent">查询</el-button>
                        </el-col>
                    </el-row>
                </el-form>
            </div>
            <!--            <div class="search">-->
            <!--                <div class="email"><label>邮箱：</label><input type="email"></input></div>-->
            <!--            </div>-->
        </div>
        <!--表格-->
        <div class="ope table" v-loading="loading">
            <el-table ref="table" :data="table.data" header-row-class-name="tab_header" :cell-style="myCellStyle"
                      style="width: 100%;font-size: 12px;padding-right: 20px;" height="100%"
                      @selection-change="handleSelectionChange">
                <el-table-column type="selection" fixed></el-table-column>
                <el-table-column align="center" prop="id" label="ID" min-width="36"></el-table-column>
                <el-table-column align="center" prop="fullName" label="企业名称" min-width="240"></el-table-column>
                <el-table-column align="center" prop="contactName" label="联系人" min-width="70"></el-table-column>
                <el-table-column align="center" prop="phone" label="联系电话" min-width="105"></el-table-column>
                <el-table-column align="center" prop="email" label="邮箱" min-width="140"></el-table-column>
                <el-table-column align="center" prop="type" label="企业类型"></el-table-column>
                <el-table-column align="center" prop="nature" label="企业性质"></el-table-column>
                <el-table-column align="center" prop="city" label="所在地" min-width="60"></el-table-column>
                <el-table-column align="center" prop="name" label="顾问" min-width="100">
                    <template slot-scope="scope">
                        <el-select v-model="scope.row.name" placeholder="请选择"
                                   @change="selectOne(scope.row.name,scope.row.id)">
                            <el-option
                                    v-for="item in options"
                                    :key="item.id"
                                    :label="item.value"
                                    :value="item.label">
                            </el-option>
                        </el-select>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="状态">
                    <template slot-scope="scope">
                        <div class="ltabStatus">{{scope.row.checkState|stateFilter}}</div>
                    </template>
                </el-table-column>
                <el-table-column align="center" min-width="60" prop="state" fixed="right" label="操作">
                    <template slot-scope="scope">
                        <el-button type="text" @click="doclick(scope.row)">查看</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <el-pagination
                style="text-align: right;margin-right: 40px"
                background
                @current-change="pageChange"
                :current-page.sync="query.currPageNo"
                :page-size="query.pageSize"
                layout="total,prev, pager, next"
                :total="table.total"
        ></el-pagination>
    </div>
</template>

<script>
    import DbSelector from '@/components/selectors/DbSelector'

    export default {
        name: 'DatabaseTalents',
        components: {DbSelector},
        data() {
            return {
                options: [],
                loading: false,
                query: {
                    currPageNo: 1,
                    pageSize: 30,
                    fullName: undefined,
                    name: undefined,
                    phone: undefined,
                    city: undefined,
                    contactName: undefined,
                    type: undefined,
                    checkState: undefined
                },
                table: {
                    data: [],
                    total: 1
                },
                value: 0,
                checkList: []
            }
        },
        methods: {
            myCellStyle({row, column, rowIndex, columnIndex}) {
                // return 'padding:0px;border:1px solid red';
                return 'padding:0px;';
            }, selectOne(item, cid) {
                this.lAxios({
                    method: 'post',
                    url: '/platform/saveConsultant.do',
                    params: {companyId: cid, platformUserId: this.findGwId(item)}
                }).then(res => {
                    res = res.data;
                    if(res.status == 0){
                        this.$message.success("保存成功！");
                    }else{
                        this.$message.error("保存失败！");
                    }
                })
            },
            findGwId(name) {
                if (this.options.length == 0) return;
                for (let item of this.options) {
                    if (name == item.label) {
                        return item.id;
                    }
                }
            },
            pageChange() {
                this.doshowTalent()
            },
            doshowTalent() {
                this.loading = true
                const params = {
                    ...this.query
                }
                this.lAxios({
                    method: 'post', //方法
                    url: '/platform/getDatabaseCompany.do', //路径，基础路径在main.js里面配置
                    params: this.$formatParams(params)
                })
                    .then(res => {
                        //成功的回调函数
                        console.log(res.data.data)
                        this.table.data = res.data.data.list
                        this.table.total = res.data.data.total
                    })
                    .finally(() => {
                        this.loading = false
                    })
            },
            handleDelete() {
                console.log(this.checkList)
                if (this.checkList.length > 0) {
                    this.$confirm('确定删除吗?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        this._doDelete()
                    })
                }
            },
            _doDelete() {
                this.loading = true
                const params = {
                    ids: this.checkList.join(',')
                }
                this.lAxios({
                    method: 'post', //方法
                    url: '/platform/deleteCompany.do', //路径，基础路径在main.js里面配置
                    params: this.$formatParams(params)
                })
                    .then(res => {
                        //成功的回调函数
                        if (res.data.status == 0) {
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            })
                            this.doshowTalent()
                        }
                    })
                    .finally(() => {
                        this.loading = false
                    })
            },
            handleSelectionChange(val) {
                this.checkList = val.map(item => {
                    return item.id
                })
            },
            doclick(row) {
                this.$router.push({
                    name: 'EnterpriseDataCont',
                    params: {id: row.id}
                })
            }
        },
        filters: {
            stateFilter(val) {
                let arr = ['待审核', '试用合作', '已合作', '暂不合作', "异常"]
                return arr[val]
            }
        },
        activated() {
            this.doshowTalent();
            this.lAxios({
                method: 'post',
                url: 'platform/getAllConsultant.do',
                params: {}
            }).then(res => {
                res = res.data;
                if (res.status == 0) {
                    this.options = [];
                    for (let item of res.data) {
                        let gu = {};
                        gu.id = item.id;
                        gu.value = item.name;
                        gu.label = item.name;
                        this.options.push(gu)
                    }
                }
                console.log("one", res);
            })
        }, mounted() {

        }
    }
</script>

<style lang="scss">
    .DatabaseTalents {
        box-sizing: border-box;
        width: 100%;
        /*height: 300px;*/
        padding-left: 10px;

        .breadcrumb {
            margin: 10px 0;
            font-size: 14px;
            color: #333;
        }

        .search_box {
            background-color: white;
            padding: 10px 50px;

            .form {
                margin-left: -20px;
                margin-top: -10px;

                .el-form {
                    .el-form-item__label {
                        font-weight: 700;
                        color: rgb(31, 46, 77);
                        font-family: 'Arial Negreta', 'Arial Normal', 'Arial';
                    }
                }

                .btn {
                    width: 140px;
                    height: 40px;
                    background-color: #37f;
                    color: #fff;
                }
            }

            input {
                height: 30px;
            }

            .table {
                .tab_header {
                    th {
                        color: rgb(31, 46, 77);
                        font-weight: 400;
                        font-size: 14px;
                        text-align: center;
                        background-color: #e6e9f0;
                    }
                }
            }
        }

        .ope {
            width: 100%;
            height: calc(100vh - 320px);
            overflow: auto;
        }
    }
</style>
